<?php
/**
 * wrapper class for role table
 * @package naanal
 */
class ClsWUserrole extends ClsWrapper
{
  /**
   * role id
   * @package naanal
   * @var string 
   */	
    protected $role_id=null;
        /**
         * user id
         * @var string 
         */
  	protected $user_id=null;
        /**
         * tablename
         * @package naanal
         * @var string 
         */
        public $pdo=null;
 	public $tableName=null;	  
	/**
         * construct
         * @package naanal
         * @param string $controlpanel
         */
        function __construct()
	{
		parent::__construct();
                $this->pdo=  ClsNaanalPDO::getNamedInstance();
	}
	/**
         * get id
         * @package naanal
         * @return integer
         */
	function get_id()
	{
		return $this->id;
	}
        /**
         * set id
         * @package naanal
         * @param integer $id
         */
	function set_id($id)
	{
		$this->id=$id;
	}
	/**
         * get role id
         * @package naanal
         * @return integer
         */
  	public function get_role_id()
  	{
  		return $this->role_id;
  	}
  	/**
         * set role id
         * @package naanal
         * @param integer $role_id
         */
  	public function set_role_id($role_id)
  	{
  		$this->role_id=$role_id;
  	}
  	/**
         * get role lookup
         * @package naanal
         * @return string
         */
  	public function get_role_lookup()
  	{
		$this->pdo->setQuery("select role.* from role,user where role.user_id=user.id and user.client_id=".getUserObject()->get_client_id());
  		$arrObj=$this->pdo->getAllAssoc("ClsWRole");
  		$select='<select name="role_id">
		<option value="">- Select -</option>';
		if($arrObj)
		foreach($arrObj as $ind=>$obj)
		{
			$selected="";
			if($obj["id"]==$this->get_role_id()) $selected=" selected";
			$select=$select.'<option value="'.$obj["id"].'"'.$selected.'>'.$obj["name"].'</option>';	
		}  		
		$select=$select.'</select>';
		return $select;
	}
	/**
         * get role
         * @package naanal
         * @return string
         */  
	public function get_role()
  	{
  		$obj = ClsWrapper::getInstance("role");
                $obj->loadObject($this->role_id);
  		return $obj;
	}
	/**
         * load
         * @package naanal
         * @return boolean
         */
	/*public function load()
  	{
  		$sql="SELECT * FROM `$this->tableName` WHERE `id`='$this->id'";
  		$this->pdo->setQuery($sql);
  		$arrRow=$this->pdo->getAllAssoc();
  		if(empty($arrRow)) return false;
  		$this->setArray($arrRow[0]);
  	}*/
	/**
         * get user lookup
         * @package naanal
         * @return string
         */
	public function get_user_lookup()
  	{
  		$objUser=getUserObject();
  		$clientid=$objUser->get_client_id();
		$this->pdo->setQuery("select * from user where client_id=".$clientid);
  		$arrObj=$this->pdo->getAllAssoc("ClsWUser");
  		$select='<select name="user_id">
		<option value="">- Select -</option>';
		foreach($arrObj as $ind=>$obj)
		{
			$selected="";
			if($obj["id"]==$this->get_user_id()) $selected=" selected";
			$select=$select.'<option value="'.$obj["id"].'"'.$selected.'>'.$obj["userid"].'</option>';	
		}  		
		$select=$select.'</select>';
		return $select;
	}   
  	/**
         * get user
         * @package naanal
         * @return string
         */
  	public function get_user()
  	{
                $obj = ClsWrapper::getInstance("user");
                $obj->loadObject($this->user_id);
  		return $obj;
	}
	/**
         * get user id
         * @package naanal
         * @return integer
         */
  	public function get_user_id()
  	{
  		return $this->user_id;
  	}
  	/**
         * set user id
         * @package naanal
         * @param integer $user_id
         */
  	public function set_user_id($user_id)
  	{
  		$this->user_id=$user_id;
  	}	  
}	
?>